<template>
  <div class="container">
    <leftcont></leftcont>
    <div class="righCont">
      <topcont></topcont>
      <div class="content">
        <div class="payTable">
          <div class="trendTop">简历列表({{ total }})</div>
          <div class="tableCont">
            <div class="tableSerchCont">
              <div class="serchItem">
                <el-select
                  v-model="biographical_notes_status"
                  placeholder="请选择简历状态"
                >
                  <el-option
                    v-for="(item, index) in statusArr"
                    :key="index"
                    :label="item.val"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </div>
              <div class="serchItem">
                <el-select v-model="is_member" placeholder="请选择会员状态">
                  <el-option
                    v-for="(item, index) in accountArr"
                    :key="index"
                    :label="item.val"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </div>
              <div class="serchItem" style="width: 250px">
                <el-input
                  v-model="serchVal"
                  placeholder="请输入用户昵称|姓名|职位"
                ></el-input>
              </div>
              <div class="headBtn">
                <btn value="搜索" @click="serchFn"></btn>
              </div>
            </div>
            <el-table :data="tableData" style="width: 100%">
              <el-table-column show-overflow-tooltip label="账号昵称">
                <template #default="scope">
                  <span>{{ scope.row.nick_name }}</span>
                  <span
                    v-if="scope.row.is_virtually == 2"
                    style="color: #f56c6c"
                    >*</span
                  >
                </template>
              </el-table-column>
              <el-table-column
                show-overflow-tooltip
                prop="real_name"
                label="真实姓名"
              >
              </el-table-column>
              <el-table-column prop="career_path" label="职位方向">
              </el-table-column>
              <el-table-column width="180" prop="mobile" label="联系电话">
              </el-table-column>
              <el-table-column
                property="channelCode"
                show-overflow-tooltip
                label="简历状态"
              >
                <template #default="scope">
                  <el-tag
                    type="success"
                    v-if="scope.row.biographical_notes_status == 1"
                    >正常</el-tag
                  >
                  <el-tag
                    type="danger"
                    v-if="scope.row.biographical_notes_status == 2"
                    >禁用</el-tag
                  >
                </template>
              </el-table-column>
              <el-table-column
                property="channelCode"
                show-overflow-tooltip
                label="会员状态"
              >
                <template #default="scope">
                  <el-tag type="info" v-if="scope.row.is_member == 1"
                    >未开通</el-tag
                  >
                  <el-tag type="success" v-if="scope.row.is_member == 2"
                    >已开通</el-tag
                  >
                  <el-tag type="danger" v-if="scope.row.is_member == 3"
                    >已到期</el-tag
                  >
                </template>
              </el-table-column>
              <el-table-column
                property="member_time"
                width="180"
                show-overflow-tooltip
                label="会员到期时间"
              >
              </el-table-column>
              <el-table-column label="操作" width="200">
                <template #default="scope">
                  <div class="ctrolBtn">
                    <div
                      class="text_btn redBtn"
                      v-if="scope.row.biographical_notes_status == 1"
                      @click="checkStatus(scope.row)"
                    >
                      禁用
                    </div>
                    <div
                      class="text_btn blueBtn"
                      v-if="scope.row.biographical_notes_status == 2"
                      @click="checkStatus(scope.row)"
                    >
                      恢复
                    </div>
                    <div class="text_btn greenBtn" @click="toDetail(scope.row)">
                      详情
                    </div>
                  </div>
                </template>
              </el-table-column>
            </el-table>
            <div class="pageCont">
              <el-pagination
                background
                layout="prev, pager, next"
                :page-size="per_page"
                :current-page="page"
                @current-change="pageFn"
                :total="total"
              >
              </el-pagination>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import leftcont from "@/components/leftCont.vue";
import topcont from "@/components/topCont.vue";
import btn from "@/components/public/btn.vue";
import { Biographicalnotes, bookCheckStatus } from "@/http/api";
import { ElMessage, ElMessageBox } from "element-plus";

export default {
  components: { leftcont, topcont, btn },
  data() {
    return {
      activeNames: "1",
      serchVal: "",
      tableData: [{}],
      page: 1,
      per_page: 5,
      total: 0,
      statusArr: [
        { val: "全部", id: "" },
        { val: "禁用", id: 1 },
        { val: "正常", id: 2 },
      ],
      biographical_notes_status: "",
      accountArr: [
        { val: "全部", id: "" },
        { val: "未开通", id: 1 },
        { val: "已开通", id: 2 },
        { val: "已到期", id: 3 },
      ],
      is_member: "",
      activeItem: {},
    };
  },
  props: {},
  methods: {
    toDetail(item) {
      this.$router.push({
        path: "/bookDetail",
        query: { id: item.biographical_notes_id },
      });
    },
    checkStatus(item) {
      if (item.biographical_notes_status == 2) {
        ElMessageBox.confirm("确认恢复当前简历状态?", "状态变更提示", {
          confirmButtonText: "确认",
          cancelButtonText: "取消",
          type: "warning",
        }).then(() => {
          let data = {
            biographical_notes_id: item.biographical_notes_id,
            biographical_notes_status: 1,
          };
          bookCheckStatus(data).then((res) => {
            if (res.data.code == 1) {
              ElMessage({
                type: "success",
                message: "修改成功",
              });
              this.getData();
            } else {
              ElMessage(res.data.msg);
            }
          });
        });
      } else {
        ElMessageBox.prompt("确认禁用当前简历?", "状态变更提示", {
          confirmButtonText: "确认",
          cancelButtonText: "取消",
          type: "warning",
        }).then((val) => {
          if (!val.value) {
            ElMessage("请输入禁用原因");
            return false;
          }
          let data = {
            biographical_notes_id: item.biographical_notes_id,
            biographical_notes_status: 2,
            jy_reason: val.value,
          };
          bookCheckStatus(data).then((res) => {
            if (res.data.code == 1) {
              ElMessage({
                type: "success",
                message: "修改成功",
              });
              this.getData();
            } else {
              ElMessage(res.data.msg);
            }
          });
        });
      }
    },
    pageFn(index) {
      this.page = index;
      this.getData();
    },
    serchFn() {
      this.page = 1;
      this.total = 0;
      this.getData();
    },
    getData() {
      var data = {
        biographical_notes_status: this.biographical_notes_status,
        is_member: this.is_member,
        search: this.serchVal,
        page: this.page,
        per_page: this.per_page,
      };
      Biographicalnotes(data)
        .then((res) => {
          if (res.data.code == 1) {
            this.tableData = res.data.data.data; //把最新的数组赋值给tableData
            this.total = res.data.data.total;
          } else {
            ElMessage(res.data.msg);
          }
        })
        .catch((err) => {
          ElMessage.error("服务器请求超时");
        });
    },
  },
  mounted() {},
  created() {
    this.getData();
  },
};
</script>

<style scoped lang="less">
.container {
  width: 100%;
  display: flex;
  height: 100vh;
  overflow: hidden;
  .righCont {
    display: flex;
    flex-direction: column;
    flex: 1;
    margin-left: 15px;
    height: 100%;
    width: 10px;
    background-color: #f4f8ff;
    .content {
      padding: 20px;
      box-sizing: border-box;
      width: 100%;
      flex: 1;
      .payTable {
        width: 100%;
        height: 100%;
        background-color: #fff;
        padding: 15px;
        border-radius: 5px;
        overflow: auto;
        box-sizing: border-box;
        .trendTop {
          font-weight: bold;
          font-size: 16px;
          cursor: pointer;
        }
        .tableCont {
          width: 100%;
          margin-top: 15px;
          .userImg {
            height: 40px;
            border-radius: 5px;
          }
          .redBtn {
            color: #f56c6c;
          }
          .blueBtn {
            color: #96a1fe;
          }
          .greenBtn {
            color: #85ce61;
          }
          .blackBtn {
            color: #666;
          }
          .tableSerchCont {
            width: 100%;
            display: flex;
            justify-content: flex-end;
            margin-bottom: 10px;
            .serchItem {
              width: 150px;
              margin-left: 10px;
            }
            .headBtn {
              margin-left: 10px;
            }
          }
          .ctrolBtn {
            display: flex;
            .text_btn {
              margin: 0 5px;
              cursor: pointer;
              font-size: 14px;
            }
          }
          .pageCont {
            padding: 30px 0;
            display: flex;
            justify-content: center;
          }
        }
      }
    }
  }
}
</style>
